package com.example.designmodel;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class StrategyActivity extends AppCompatActivity {

    public static void launch(Context context) {
        Intent intent = new Intent(context, StrategyActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_strategy);
        calcute();
    }

    private void calcute(){
//        ICalculte calculte = new Add();
//        CalculteContext calculteContext = new CalculteContext(calculte);
//        calculteContext.exec(3,4);
//
//        ICalculte calculte1 = new Sub();
//        calculteContext.setCalculte(calculte1);
//        calculteContext.exec(66,78);
        CalcuteEnum.ADD.exec(6,8);
        CalcuteEnum.SUB.exec(87,45);

    }

    public static interface ICalculte{
        void exec(int a,int b);
    }

    public static class Add implements ICalculte{
        @Override
        public void exec(int a, int b) {
            Log.i("test",a + " + " + b +" = "+(a+b));
        }
    }

    public static class Sub implements ICalculte{
        @Override
        public void exec(int a, int b) {
            Log.i("test",a + " - " + b +" = "+(a-b));
        }
    }

    public static class CalculteContext{
        private ICalculte calculte;

        public CalculteContext(ICalculte calculte) {
            this.calculte = calculte;
        }

        public ICalculte getCalculte() {
            return calculte;
        }

        public void setCalculte(ICalculte calculte) {
            this.calculte = calculte;
        }

        public void exec(int a,int b){
            this.calculte.exec(a,b);
        }
    }

    public enum CalcuteEnum{
        ADD("+"){
            @Override
            public void exec(int a, int b) {
                Log.i("test",a + " + " + b +" = "+(a + b));
            }
        },

        SUB("-"){
            @Override
            public void exec(int a, int b) {
                Log.i("test",a + " - " + b +" = "+(a - b));
            }
        };

        String value ="";

       private CalcuteEnum(String value) {
            this.value = value;
        }

        public abstract void exec(int a,int b);


    }


}
